﻿using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CastleDynamicProxyTest
{
    public class WorkProxyGenerationHook : IProxyGenerationHook
    {
        public void MethodsInspected()
        {
            
        }

        public void NonProxyableMemberNotification(Type type, MemberInfo memberInfo)
        {
            
        }

        public bool ShouldInterceptMethod(Type type, MethodInfo memberInfo)
        {
            return 
            (memberInfo.Name.StartsWith("Excute") || memberInfo.Name.StartsWith("Excute"));   //什么样的方法可以被拦截?
        }
    }

    [Obsolete("改为WorkProxyGenerationHook处理")]
    public class InterceptorSelector : IInterceptorSelector
    {
        public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
        {
            if (method.Name.StartsWith("Excute")) return interceptors;    //这里可以决定什么的方法返回什么样的拦截器
            else return interceptors.Where(i => i is WorkAsyncInterceptorWarpper).ToArray<IInterceptor>();
        }
    }
}
